home *** CD-ROM | disk | FTP | other *** search
- ;APS00000000000000000000000000000000000000000000000000000000000000000000000000000000
- * $Id: nonvolatile.s 1.1 1999/02/03 04:10:45 jotd Exp $
- **************************************************************************
- * NONVOLATILE-LIBRARY *
- **************************************************************************
- **************************************************************************
- * INITIALIZATION *
- **************************************************************************
-
- NONVINIT move.l _nonvbase,d0
- beq .init
- rts
-
- .init move.l #162,d0 ; reserved function
- move.l #80,d1 ; 20 variables: should be OK
- lea _nonvname,a0
- bsr _InitLibrary
- move.l d0,a0
- move.l d0,_nonvbase
-
- patch _LVOGetCopyNV(a0),GETCOPYNV
- patch _LVOStoreNV(a0),STORENV
- patch _LVOGetNVInfo(a0),_GetNVInfo
- ; patch _LVOGetNVList(a0),_GetNVList
- patch _LVOFreeNVData(A0),FREENVDATA
-
- rts
-
- ;GetNVInfo[APTR d0](killrequesters [bool D1])
- _GetNVInfo:
- ; moveq #0,D0 ; not available
- moveq.l #8+8,d0
- moveq.l #0,d1
- bsr.w ForeignAllocMem
- tst.l d0
- beq.s .rts
- move.l d0,a0
- move.l d0,(A0)+
- move.l #8+8,(A0)+
- move.l #999900,(A0) ;total storage on nv-device
- move.l #989800,4(A0) ;free storage on nv-device
- move.l a0,d0
- .rts rts
-
-
- ;GetCopyNV[APTR d0](appname[strptr a0],itemname[strptr a1],
- ; killrequesters[bool d1])
- ;caveats: if appname+itemname becomes >32 chars the function will show
- ; a requester indicating theres a problem within the function
- ; (not likely as programmers chose them short to save NVRAM-space)
- GETCOPYNV:
- link a5,#-$40
- ;assemble filename, <appname>_<itemname>\0
- MOVEM.L a0-a3,-(A7)
- lea.l 4*4+4(A7),a2
- .cpappname tst.b (A0)
- beq.s .endappname
- move.b (A0)+,(A2)+
- bra.s .cpappname
-
- .endappname move.b #'_',(A2)+
- .cpitemname tst.b (A1)
- beq.s .enditemname
- move.b (A1)+,(A2)+
- bra.s .cpitemname
-
- .enditemname move.b #0,(A2)+
-
- ;check if file exists
- lea.l 4*4+4(A7),a0
- sub.l a0,a2
- cmp.l #32,a2
- bls.s .filename_ok
- pea _LVOGetCopyNV
- pea _nonvname
- bra _emufail
-
- .filename_ok move.l _RESLOAD(pc),a2
- jsr (resload_GetFileSize,a2)
- tst.l d0
- beq.s .notexisting
-
- ;reserve mem
- add.l #$8+7,d0
- and.w #$fff8,d0
- move.l d0,4*4+4+$38(A7)
- clr.l d1
- bsr.w ForeignAllocMem
- tst.l d0
- beq.s .notexisting
-
- ;header:
- move.l d0,a3
- move.l d0,(A3)+
- move.l 4*4+4+$38(A7),d1
- move.l d1,(A3)+
-
- ;load file into mem
- addq.l #8,d0
- move.l d0,a1
- lea.l 4*4+4(A7),a0
- move.l _RESLOAD(pc),a2
- jsr (resload_LoadFile,a2)
-
- move.l a3,d0
- MOVEM.L (A7)+,a0-a3
- unlk a5
- rts
-
- .notexisting moveq #0,D0
- MOVEM.L (A7)+,a0-a3
- unlk a5
- rts
-
- ;FreeNVData(data[APTR A0])
-
- FREENVDATA
- move.l a0,d0
- beq.s .rts
- move.l -8(A0),a1
- move.l -4(A0),d0
- bsr.w ForeignFreeMem
-
- .rts rts
-
- ;; StoreNV [error - UWORD d0](appName[STRPTR a0], itemName[STRPTR A1],
- ; data[APTR a2],length[ULONG d0], killRequesters[BOOL d1])
-
-
- STORENV:
- link a5,#-$40
- ;assemble filename, <appname>_<itemname>\0
- MOVEM.L a2/d0/d2-d3,-(A7)
- lea.l 4*4+4(A7),a2
- .cpappname tst.b (A0)
- beq.s .endappname
- move.b (A0)+,(A2)+
- bra.s .cpappname
-
- .endappname move.b #'_',(A2)+
- .cpitemname tst.b (A1)
- beq.s .enditemname
- move.b (A1)+,(A2)+
- bra.s .cpitemname
-
- .enditemname move.b #0,(A2)+
-
- ;check if file exists
- lea.l 4*4+4(A7),a0
- sub.l a0,a2
- cmp.l #32,a2
- bls.s .filename_ok
- pea _LVOStoreNV
- pea _nonvname
- bra _emufail
-
- .filename_ok
- ;save with dos to ensure to wipe out illegal pathnames
- move.l a0,d1
- MOVE.L #MODE_NEWFILE,D2
- BSR.W _Open
- TST.L D0
- beq.s .err
- move.l d0,a2
- move.l d0,d1
- move.l $c(A7),d2
- move.l (A7),d3 ;multiply len by 10
- lsl.l #2,d3
- add.l (A7),d3
- add.l d3,d3
- bsr.w _Write
- ;ignore any error
- move.l a2,d1
- bsr.w _Close
-
- .err movem.l (A7)+,a2/d0/d2-d3
- moveq #0,D0
- unlk a5
- rts
-
-
- ;GetNVList[AppName A0](killrequesters [bool D1])
-
- _GetNVList:
- movem.l D2-D3/A2-A3,-(A7)
- move.l A0,A3 ; appname
-
- move.l #MLH_SIZE,D0
- move.l #MEMF_CLEAR,D1
- bsr ForeignAllocMem
- tst.l D0
- beq.b .end
- move.l D0,A1
- INITLIST
-
- move.l #300,D0
- move.l #MEMF_CLEAR,D1
- bsr ForeignAllocMem
- tst.l D0
- beq.b .end
-
- move.l D0,D2 ; buffer
-
- move.l D0,A1
- LEA .thisdir(pc),A0 ;filename
- move.l _RESLOAD(PC),a2
- move.l #300,D0 ; buffer size
- jsr (resload_ListFiles,a2)
-
- ; files read, now scan names and find the ones
- ; starting by AppName'_'
-
- move.l D2,A0
-
-
- .end
- movem.l (A7)+,D2-D3/A2-A3
- rts
- .thisdir:
- dc.b 34,34,0
- cnop 0,4
-
-